package com.darren.euc.dao.impl;


import java.util.List;

import org.hibernate.CacheMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.darren.euc.dao.HanWangRecordDao;
import com.darren.euc.entity.HanWangRecord;


@Repository
public class HanWangRecordDaoImpl extends BaseDaoImpl<HanWangRecord, Integer> implements HanWangRecordDao {
	
	@SuppressWarnings("unchecked")
	@Override
	public List<HanWangRecord> getAll() {
		Session session = sessionFactory.getCurrentSession();
		Query query  = session.createQuery("from HanWangRecord where enable=true");
		query.setCacheMode(CacheMode.IGNORE);
		List<HanWangRecord> hanWangDoors = query.list();
		return hanWangDoors;
	}
	
	
	@Override
	public HanWangRecord getLastRecord() {
		Session session = sessionFactory.getCurrentSession();
		Query query  = session.createQuery(" from HanWangRecord order by openDoorTime desc ");
		HanWangRecord hanWangDoor = (HanWangRecord) query.uniqueResult();
		return hanWangDoor;
	}

	
	
}